package com.service.ua;

import com.bpms.common.CreateID;
import com.bpms.common.Db;
import com.bpms.common.Tools;
import com.bpms.common.VO;
import com.bpms.esb.IService;

public class Logout implements IService {

	/**
	 * 输入参数
	 * userid	用户id
	 * sysid   系统登录权限
	 * 输出参数
	 * result 0000成功 1111失败 9999其他
	 * msg 描述
	 * user信息
	 */
	public VO exec(VO args) {
		VO vo=new VO();
		
		if(args==null) {
			vo.setAttr("result", "9999");
			vo.setAttr("msg", "系统异常，参数为空");
			return vo;
		}
		try {
			Db j=new Db();
			VO uservo=j.readInCombination(new VO(), "select * from BPM_USER where userid='"+args.getAttr("USERID")+"'");
			if(uservo==null){
				vo.setAttr("result", "9999");
				vo.setAttr("msg", "用户信息不存在，登出失败");
				return vo;
			}
//			if(!uservo.getAttr("PASSWD").equals(args.getAttr("PASSWD"))) return null;
			
			VO keyVO=new VO();
			VO updateVO=new VO();
			keyVO.voType="bpm_user";
			keyVO.isAutoKey=false;
			keyVO.keyString="userid";
			keyVO.setAttr("userid",args.getAttr("USERID"));
			updateVO.setAttr("logstatus","logout");
			j.update(updateVO, keyVO);

			
			VO v=new VO();
			v.voType="UA_USERLOG";
			String ID=CreateID.I().CreateCheckID("UA_USERLOG");
			v.setAttr("ID", ID);
			v.setAttr("USERID", uservo.getAttr("USERID"));
			v.setAttr("SYSID", args.getAttr("SYSID"));
			v.setAttr("USERACTION", "LOGOUT");
			v.setAttr("CDATE", Tools.getDate());
			v.setAttr("CTIME", Tools.getTime());
			j.insert(v);
			
			uservo.setAttr("result", "0000");
			return uservo;
			
		} catch (Exception e) {
			
			vo.setAttr("result", "9999");
			vo.setAttr("msg", "系统异常");
			return vo;
		}
		
	}

}
